package currency;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

class AtomicTest extends Accumulator {
    private AtomicInteger mThisIndex = new AtomicInteger(0);

    private AtomicLong mThisValue = new AtomicLong(0);

    {
        mId = "Atomic";
    }

    @Override
    public void accumulate() {
        // Oops! Relying on more than one Atomic at
        // a time doesn't work. But it still gives us
        // a performance indicator
        int i = mThisIndex.get();
        mThisValue.getAndAdd(sPreLoaded[i]);
        if(++i >= SIZE)
            mThisIndex.set(0);
    }

    @Override
    public long read() {
        return mThisValue.get();
    }
}
